/* 쿠기를 이용한 아이디 저장부분 */
function setSaveId() {
	var expdate = new Date();
	if ($("#loginFrm input[name='saveId']").attr("checked", "checked")) {
	    expdate.setTime(expdate.getTime() + 1000 * 3600 * 24 * 30); // 30day
	} else {
	    expdate.setTime(expdate.getTime() + (-1*1000 * 3600 * 24 * 30)); // -30day
	}

	setCookie("SAVE_ID", $("#loginFrm input[name='memId']").val(), expdate);

	if ($("#loginFrm input[name='savePwd']").attr("checked", "checked")) {
	    expdate.setTime(expdate.getTime() + 1000 * 3600 * 24 * 30); // 30day
	} else {
	    expdate.setTime(expdate.getTime() + (-1*1000 * 3600 * 24 * 30)); // -30day
	}

	setCookie("SAVE_PWD", $("#loginFrm input[name='memPwd']").val(), expdate);
}

/* 쿠키에 해당 항목, 값을 저장 */
function setCookie (name, value, expires) {
	document.cookie = name + "=" + escape (value) + "; path=/; domain=.ododoc.com; expires=" + expires.toGMTString();
}

/* 아이디 저장 부분을 실행 */
function initPage() {
	var saveId = getCookie("SAVE_ID");
	var savePwd = getCookie("SAVE_PWD");

	if (saveId != null && saveId !="" ) {
        $("#loginFrm input[name='memId']").val(saveId);
        $("#loginFrm input[name='saveId']").attr("checked", "checked");
        $("#loginFrm input[name='memPwd']").focus();
    } else {
    	$("#loginFrm input[name='memId']").focus();
    }

	if (savePwd != null && savePwd !="" ) {
		$("#loginFrm input[name='memPwd']").val(savePwd);
        $("#loginFrm input[name='savePwd']").attr("checked", "checked");
       $("#loginFrm button[name='login']").focus();
    } else {
    	$("#loginFrm input[name='memPwd']").focus();
    }
}

/* 쿠키값을 가져오는 부분 */
function getCookie(name) {
	var stName = name;

	stName += "=";
	var nCookieLen = document.cookie.length;

    var nStart = document.cookie.indexOf( stName);
    if( nStart == -1) return "";
    if( nStart + stName.length >= nCookieLen) return "";

    var nEnd = nStart + stName.length;
    if( document.cookie.charAt( nEnd) == ';') return "";
    nStart = nEnd;
    nEnd = document.cookie.indexOf(";", nEnd);
    if( nEnd == -1) nEnd = document.cookie.length;

    return document.cookie.substring( nStart, nEnd);
}

/* 쿠키를 삭제하는 부분 */
function deleteCookie(name, path, domain) {
	var varName = getCookie(name);

	if (varName != "") {
		document.cookie = varName + "=" + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + '; expires=Thu, 01-Jan-70 00:00:01 GMT';
	}
}

/* 아이디 저장을 해제하는 부분 */
function expireCookie() {
	deleteCookie("SAVE_ID", "/", ".ododoc.com");
	deleteCookie("SAVE_PWD", "/", ".ododoc.com");
}
